package com.mzj.saas.mservice.lock.Repository;

import com.mzj.saas.mservice.lock.entity.SmartLockPwd;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface SmartLockPwdRepository extends PagingAndSortingRepository<SmartLockPwd, Long>, JpaSpecificationExecutor<SmartLockPwd> {
    @Transactional
    void deleteByLockAuthId(Long lockAuthId);
    void deleteByLockAuthIdAndType(Long lockAuthId,Integer type);

    SmartLockPwd findByLockAuthId(Long lockAuthId);

    @Transactional
    @Modifying
    @Query(value = "UPDATE saas_smart_lock_pwd set identification=?1 where id=?2", nativeQuery = true)
    int setIdentification(String identification, Long id);

    List<SmartLockPwd> findByLockId(Long lockId);

    SmartLockPwd findByLockAuthIdAndType(Long lockAuthId, Integer type);
    SmartLockPwd findByIdentification(String identification);

    SmartLockPwd findByLockAuthIdAndPwdIndex(Long lockAuthId, Integer pwdIndex);
    
    SmartLockPwd findByLockIdAndPwdIndex(Long lockId, Integer pwdIndex);
    
    SmartLockPwd findByLockIdAndPwdIndexNum(Long lockId, Integer pwdIndexNum);

    @Modifying
    int deleteByLockId(Long lockId);

}
